package com.xcity.game.adventure.template;

import com.xcity.game.adventure.AdventureType;
import com.xcity.game.common.GameStaticConfig;

import naga.x.game.template.Template;
import naga.x.game.template.TemplateException;
import naga.x.game.template.annotation.Excel;

/**
 * 奇遇v2
 * @author yang.li
 *
 */
@Excel(value = "turntable.xlsx", sheetName = "奇遇v2")
public class AdventureTemplate extends Template /*implements Interval*/ {

	/** 类型（1：现金，2：护盾，3：体力，4：物品/建材箱，5：偷窃，6：攻击） */
	protected AdventureType type;

	/** 数值（类型为1时表示现金数，3：体力数，4：物品id） */
	protected int data;
	
	/** 图标 */
	protected String icon;

	/** 抽中概率（整数） */
	protected int[] probability;
	
//	protected int weightStart, weight;
//	public static int maxProbability;
	protected int[] probabilityFrom = new int[WEIGHT_GROUP_SIZE];
	
	// 概率组数
	public static final int WEIGHT_GROUP_SIZE = 7;
	
	public static AdventureTemplate capture = new AdventureTemplate();
	static {
		capture.setId(GameStaticConfig.adventureCaptureFuncPos + 1);
		capture.setType(AdventureType.CAPTURE);
		capture.setIcon("item_attack.png");
	}

	public AdventureType getType() {
		return type;
	}

	public void setType(AdventureType type) {
		this.type = type;
	}

	public int getData() {
		return data;
	}

	public void setData(int data) {
		this.data = data;
	}

	public String getIcon() {
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	public int[] getProbability() {
		return probability;
	}

	public void setProbability(int[] probability) {
		this.probability = probability;
	}
	
	public int getWeightFrom(int index) {
		return probabilityFrom[index];
	}
	
	public int getWeightTo(int index) {
		return probability[index];
	}
	
	public void setWeight(int index, int weightFrom, int weightTo) {
		probabilityFrom[index] = weightFrom;
		probability[index] = weightTo;
	}
	
	@Override
	public void validate() throws TemplateException {
		if (type == null || type == AdventureType.UNKNOWN
				|| probability == null || probability.length != WEIGHT_GROUP_SIZE) {
			throw new TemplateException("turntable.xlsx->奇遇v2 配置错误: id = " + id);
		}
		
//		weightStart = maxProbability;
//		maxProbability += probability;
//		weight = maxProbability;
		
	}

//	@Override
//	public int getMinVal() {
//		return weightStart;
//	}
//
//	@Override
//	public int getMaxVal() {
//		return weight;
//	}
}
